﻿using Consul;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace Basic.Cluster.Manager
{
    public class ConsulManager
    {
        private List<AgentServiceRegistration> ServiceList;
        private List<ConsulClient> ClientList;

        public ConsulManager()
        {

        }

        public ConsulManager(List<AgentServiceRegistration> serviceList)
        {
            if (serviceList.Count == 0)
                throw new ArgumentNullException(nameof(serviceList));

            ServiceList = serviceList;
            ClientList = new List<ConsulClient>(serviceList.Count);

            Initialization();
        }

        private void Initialization()
        {
            foreach (var conf in ServiceList)
            {
                ConsulClient consulClient = new ConsulClient(s =>
                {
                    s.Address = new Uri($"{conf.Address}:{conf.Port}");
                });
                ClientList.Add(consulClient);
            }
        }

    }
}